<#import "/WEB-INF/sys/js_css.html" as js>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>权限用户配置</title>
</head>
<body>
<body class="easyui-layout">
	<!-- 菜单框架 -->
	<div data-options="region:'west'" style="width:200px;">
		<div class="easyui-accordion" data-options="fit:true,border:false">
			<div title="权限选择" data-options="selected:true">
				<div class="zTreeDemoBackground left">
					<ul id="menuTree" class="ztree"></ul>
				</div>
			</div>
		</div>
	</div>
	<!-- 主页面 -->
	<div data-options="region:'center',title:'用户信息'">
		<!-- 工具条 -->
		<div id="tools" style="padding:5px;height:auto">
			<a href="javascript:void(0)" id="btn_top_add" class="easyui-linkbutton" iconCls="icon-add" plain="true">保存权限配置</a>
		</div>
		<!-- 用户信息 -->
		<table id="datagrid" class="easyui-datagrid" data-options="singleSelect:true,fit:true,fitColumns:true,pagination:true,
			url:'${ctx}/sys/user/search',toolbar:'#tools',rownumbers : true,pageSize:15,pageList:[5,10,15,20],onSelect:selectone">
			   <thead>
				<tr>
					<th data-options="field:'id',hidden:true">id</th><!-- hidden -->
					<th data-options="field:'username',width:20,align:'center'">用户名</th>
					<th data-options="field:'sitename',width:35,align:'center'">管理站点</th>
					<th data-options="field:'mail',align:'center',width:20">邮箱</th>
					<th data-options="field:'regtime',align:'center',width:15">注册时间</th>
				</tr>
			</thead>
		</table>
	</div>
</body>
</body>
</html>
<@js.easyui />
<@js.zTree />
<script type="text/javascript">
jQuery(document).ready(function() {
	//保存权限配置按钮事件
	jQuery("#btn_top_add").click(function(){
		var row = jQuery("#datagrid").datagrid("getSelected");
		if(!row){
			jQuery.messager.alert("信息","请先选择一个用户配置权限后再保存！","error");
			return;
		}
		var id = row.id;
		jQuery.ajax({
			async:false,
			type:"post",
			dataType:"json",
			data:{id:id,authors:param},
			url:"${ctx}/sys/menu/adduseauth",
			success:function(date){
				var message = date.message;
				if(date.success)
					jQuery.messager.alert("信息",message,"info");
				else
					jQuery.messager.alert("信息",message,"error");
			}
		});
	});
	//初始化权限
	jQuery.fn.zTree.init(jQuery("#menuTree"), initTreeSetting());
});
var param = "";
function initTreeSetting(){
	var setting = {
		data: {
			simpleData: {
				enable: true
			}
		},
		check: {
			enable: true,
			chkboxType: { "Y" : "p", "N" : "p"}
		},
		view: {
			dblClickExpand: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		async: {
			enable: true,
			type:"post",
			otherParam:{"checked":param},
			url:"${ctx}/sys/menu/leftallmenu"
		},
		callback: {
			beforeClick:beforeClick,
			onCheck:onCheck
		}
	};
	return setting;
}
//副栏目节点点击之前的事件
function beforeClick(treeId, treeNode) {
	var zTree = jQuery.fn.zTree.getZTreeObj("menuTree");
	zTree.checkNode(treeNode, !treeNode.checked, null, true);
	return false;
}
//副栏目节点选择的事件
function onCheck(e, treeId, treeNode) {
	var zTree = jQuery.fn.zTree.getZTreeObj("menuTree"),
	nodes = zTree.getCheckedNodes(true),
	tempid = "";
	for (var i=0, l=nodes.length; i<l; i++) {
		tempid += nodes[i].entityid + ",";
	}
	if (tempid.length > 0 ) param = tempid.substring(0, tempid.length-1);
}
function selectone(rowIndex, rowData){
	var id = rowData.id;
	jQuery.ajax({
		async:false,
		type:"post",
		dataType:"json",
		data:{id:id},
		url:"${ctx}/sys/menu/beanuseauth",
		success:function(date){
			if(!date.success){
				jQuery.messager.alert("信息",date.message,"error");
			}
			param = date.authorids
		}
	});
	jQuery.fn.zTree.init(jQuery("#menuTree"), initTreeSetting());
}
</script>